<template>
  <el-select v-model="machineId" filterable @change="selectMethod" placeholder="请选择设备">
    <el-option
      v-for="item in allMachine"
      :key="item.id"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
</template>
  
  <script>
import { mapState } from 'vuex';
import { clone, findIndex, uniqBy, find, uniq } from 'lodash';
export default {
  name: 'fileUpLoad',
  props: {
    show: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
        machineId:'',
        allOrgData:[],
        allMachine:[]
    };
  },
  computed: {
    ...mapState({
      userInfo: state => state.app.userInfo,
      uploadPartInfo: (state) => state.resource.uploadPartInfo,
      uploadLayoutInfo: (state) => state.resource.uploadLayoutInfo
    })
  },
  watch: {
    show(val) {
      if(val){
        this.machineId='';
      }
    }
  },
  created() {
    this.getOrgList()
  },
  methods: {
    getOrgList() {
      this.$http
        .get(this.$API.ORGANIZATION, { companyId: this.userInfo.company.id })
        .then(res => {
          let list = Array.isArray(res.data) ? res.data : [];
          list=list.filter(o=>{return o.organType == 2});
          this.allOrgData = list;
          this.machineAjaxMethod()
        })
    },
    //设备
    machineAjaxMethod() {
      let keys = this.allOrgData.map(item => item.id);
      this.$http
        .post(this.$API.MACHINE,keys)
        .then(res => {
          this.allMachine = Array.isArray(res.data)?res.data:[];
        })
    },
    selectMethod(){
        let item=find(this.allMachine,o=>o.id == this.machineId)
        this.$emit('update:machine',item);
    }
  }
};
  </script>
  
  <style scoped>
.input-with-select {
}
</style>
  